﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThaiHoa.Win.QLSX.Entity;
using ThaiHoa.Win.QLSX.Kho.UI;
using System.Windows.Forms;

namespace ThaiHoa.Win.QLSX.Kho
{
    public class Access
    {
        #region Fields
        Form form;

       // frmThepDacDetail_old _frmThepDacDetail;
        //frmThepOngDetail_old _frmThepOngDetail;
        //frmThepTamDetail_old _frmThepTamDetail;
        //frmThepLuoiDetail_old _frmThepLuoiDetail;
        //frmTonDetail_old _frmTonDetail;
        frmMacVatTu _frmMacVatTu;
        frmTonKhoToiThieu _frmTonKhoToiThieu;
        frmDinhMucVatTu _frmDinhMucVatTu;
        frmLoaiMayMoc_old _frmLoaiMayMoc;

        frmNhapKho _frmNhapKho;
        frmXuatKho _frmXuatKho;
        frmDonDatHang _frmDonDatHang;

        //List
        frmMayMocList _frmMayMocList;
        frmThanhPhamList _frmThanhPhamList;
           
        frmThepDacList _frmThepDacList;
        frmThepLuoiList _frmThepLuoiList;
        frmThepOngList _frmThepOngList;
        frmThepTamList _frmThepTamList;
        frmTonList _frmTonList;
        frmMacVatTuList _frmMacVatTuList;
        frmDoiTacList _frmDoiTacList;
        frmDonViTinhList _frmDonViTinhList;
        frmLoaiMayMocList _frmLoaiMayMocList;
        frmCongCuDungCuList _frmCongCuDungCuList;

        //Detail
        frmMayMocDetail _frmMayMocDetail;
        frmThanhPhamDetail _frmThanhPhamDetail;
        
        
        frmThepDacDetail _frmThepDacDetail;
        frmThepLuoiDetail _frmThepLuoiDetail;
        frmThepOngDetail _frmThepOngDetail;
        frmThepTamDetail _frmThepTamDetail;
        frmTonDetail _frmTonDetail;
        frmMacVatTuDetail _frmMacVatTuDetail;
        frmDoiTacDetail _frmDoiTacDetail;
        frmNguoiDaiDienDetail _frmNguoiDaiDienDetail;
        frmDonViTinhDetail _frmDonViTinhDetail;
        frmLoaiMayMocDetail _frmLoaiMayMocDetail;
        frmCongCuDungCuDetail _frmCongCuDungCuDetail;

        #endregion
        public void ShowFormMacVatTu()
        {
            if (_frmMacVatTu == null || _frmMacVatTu.IsDisposed)
            {
                _frmMacVatTu = new frmMacVatTu();
                _frmMacVatTu.Show();
            }
            else
            {
                _frmMacVatTu.Activate();
            }
        }
        //public void ShowFormThepDac()
        //{
        //    if (_frmThepDacDetail == null || _frmThepDacDetail.IsDisposed)
        //    {
        //        _frmThepDacDetail = new frmThepDacDetail_old();
        //        _frmThepDacDetail.Show();
        //    }
        //    else
        //    {
        //        _frmThepDacDetail.Activate();
        //    }
        //}
        //public void ShowFormThepOng()
        //{
        //    if (_frmThepOngDetail == null || _frmThepOngDetail.IsDisposed)
        //    {
        //        _frmThepOngDetail = new frmThepOngDetail_old();
        //        _frmThepOngDetail.Show();
        //    }
        //    else
        //    {
        //        _frmThepOngDetail.Activate();
        //    }
        //}
        public void ShowFormThepTam()
        {
            //if (_frmThepTamDetail == null || _frmThepTamDetail.IsDisposed)
            //{
            //    _frmThepTamDetail = new frmThepTamDetail_old();
            //    _frmThepTamDetail.Show();
            //}
            //else
            //{
            //    _frmThepTamDetail.Activate();
            //}
        }
        public void ShowFormThepLuoi()
        {
            //if (_frmThepLuoiDetail == null || _frmThepLuoiDetail.IsDisposed)
            //{
            //    _frmThepLuoiDetail = new frmThepLuoiDetail_old();
            //    _frmThepLuoiDetail.Show();
            //}
            //else
            //{
            //    _frmThepLuoiDetail.Activate();
            //}
        }
        public void ShowFormTon()
        {
            //if (_frmTonDetail == null || _frmTonDetail.IsDisposed)
            //{
            //    _frmTonDetail = new frmTonDetail_old();
            //    _frmTonDetail.Show();
            //}
            //else
            //{
            //    _frmTonDetail.Activate();
            //}
        }
        public void ShowFormTonKhoToiThieu()
        {
            if (_frmTonKhoToiThieu == null || _frmTonKhoToiThieu.IsDisposed)
            {
                _frmTonKhoToiThieu = new frmTonKhoToiThieu();
                _frmTonKhoToiThieu.Show();
            }
            else
            {
                _frmTonKhoToiThieu.Activate();
            }
        }
        public void ShowFormDinhMucVatTu()
        {
            if (_frmDinhMucVatTu == null || _frmDinhMucVatTu.IsDisposed)
            {
                _frmDinhMucVatTu = new frmDinhMucVatTu();
                _frmDinhMucVatTu.Show();
            }
            else
            {
                _frmDinhMucVatTu.Activate();
            }
        }
        public void ShowFormLoaiMayMoc()
        {
            if (_frmLoaiMayMoc == null || _frmLoaiMayMoc.IsDisposed)
            {
                _frmLoaiMayMoc = new frmLoaiMayMoc_old();
                _frmLoaiMayMoc.Show();
            }
            else    
            {
                _frmLoaiMayMoc.Activate();
            }
        }

        //
        public void ShowFormNhapKho()
        {
            if (_frmNhapKho == null || _frmNhapKho.IsDisposed)
            {
                _frmNhapKho = new frmNhapKho();
                _frmNhapKho.MdiParent = form;
                _frmNhapKho.WindowState = FormWindowState.Maximized;
                _frmNhapKho.Show();
            }
            else
            {
                _frmNhapKho.Activate();
            }
        }
        public void ShowFormXuatKho()
        {
            if (_frmXuatKho == null || _frmXuatKho.IsDisposed)
            {
                _frmXuatKho = new frmXuatKho();
                _frmXuatKho.MdiParent = form;
                _frmXuatKho.WindowState = FormWindowState.Maximized;
                _frmXuatKho.Show();
            }
            else
            {
                _frmXuatKho.Activate();
            }
        }
        public void ShowFormDonDatHang()
        {
            if (_frmDonDatHang == null || _frmDonDatHang.IsDisposed)
            {
                _frmDonDatHang = new frmDonDatHang();
                _frmDonDatHang.MdiParent = form;
                _frmDonDatHang.WindowState = FormWindowState.Maximized;
                _frmDonDatHang.Show();
            }
            else
            {
                _frmDonDatHang.Activate();
            }
        }

        //List
        public void ShowFormMayMocList()
        {
            if (_frmMayMocList == null || _frmMayMocList.IsDisposed)
            {
                _frmMayMocList = new frmMayMocList();
                _frmMayMocList.MdiParent = form;
                _frmMayMocList.WindowState = FormWindowState.Maximized;
                _frmMayMocList.Show();
            }
            else
            {
                _frmMayMocList.Activate();
            }
        }
        public void ShowFormThanhPhamList()
        {
            if (_frmThanhPhamList == null || _frmThanhPhamList.IsDisposed)
            {
                _frmThanhPhamList = new frmThanhPhamList();
                _frmThanhPhamList.MdiParent = form;
                _frmThanhPhamList.WindowState = FormWindowState.Maximized;
                _frmThanhPhamList.Show();
            }
            else
            {
                _frmThanhPhamList.Activate();
            }
        }
        

        
        
        public void ShowFormThepDacList()
        {
            if (_frmThepDacList == null || _frmThepDacList.IsDisposed)
            {
                _frmThepDacList = new frmThepDacList();
                _frmThepDacList.MdiParent = form;
                _frmThepDacList.WindowState = FormWindowState.Maximized;
                _frmThepDacList.Show();
            }
            else
            {
                _frmThepDacList.Activate();
            }
        }
        public void ShowFormThepLuoiList()
        {
            if (_frmThepLuoiList == null || _frmThepLuoiList.IsDisposed)
            {
                _frmThepLuoiList = new frmThepLuoiList();
                _frmThepLuoiList.MdiParent = form;
                _frmThepLuoiList.WindowState = FormWindowState.Maximized;
                _frmThepLuoiList.Show();
            }
            else
            {
                _frmThepLuoiList.Activate();
            }
        }
        public void ShowFormThepOngList()
        {
            if (_frmThepOngList == null || _frmThepOngList.IsDisposed)
            {
                _frmThepOngList = new frmThepOngList();
                _frmThepOngList.MdiParent = form;
                _frmThepOngList.WindowState = FormWindowState.Maximized;
                _frmThepOngList.Show();
            }
            else
            {
                _frmThepOngList.Activate();
            }
        }
        public void ShowFormThepTamList()
        {
            if (_frmThepTamList == null || _frmThepTamList.IsDisposed)
            {
                _frmThepTamList = new frmThepTamList();
                _frmThepTamList.MdiParent = form;
                _frmThepTamList.WindowState = FormWindowState.Maximized;
                _frmThepTamList.Show();
            }
            else
            {
                _frmThepOngList.Activate();
            }
        }
        public void ShowFormTonList()
        {
            if (_frmTonList == null || _frmTonList.IsDisposed)
            {
                _frmTonList = new frmTonList();
                _frmTonList.MdiParent = form;
                _frmTonList.WindowState = FormWindowState.Maximized;
                _frmTonList.Show();
            }
            else
            {
                _frmTonList.Activate();
            }
        }
        public void ShowFormMacVatTuList()
        {
            if (_frmMacVatTuList == null || _frmMacVatTuList.IsDisposed)
            {
                _frmMacVatTuList = new frmMacVatTuList();
                _frmMacVatTuList.MdiParent = form;
                _frmMacVatTuList.WindowState = FormWindowState.Maximized;
                _frmMacVatTuList.Show();
            }
            else
            {
                _frmMacVatTuList.Activate();
            }
        }
        public void ShowFormDoiTacList()
        {
            if (_frmDoiTacList == null || _frmDoiTacList.IsDisposed)
            {
                _frmDoiTacList = new frmDoiTacList();
                _frmDoiTacList.MdiParent = form;
                _frmDoiTacList.WindowState = FormWindowState.Maximized;
                _frmDoiTacList.Show();
            }
            else
            {
                _frmDoiTacList.Activate();
            }
        }
        public void ShowFormDonViTinhList()
        {
            if (_frmDonViTinhList == null || _frmDonViTinhList.IsDisposed)
            {
                _frmDonViTinhList = new frmDonViTinhList();
                _frmDonViTinhList.MdiParent = form;
                _frmDonViTinhList.WindowState = FormWindowState.Maximized;
                _frmDonViTinhList.Show();
            }
            else
            {
                _frmDoiTacList.Activate();
            }
        }
        public void ShowFormLoaiMayMocList()
        {
            if (_frmLoaiMayMocList == null || _frmLoaiMayMocList.IsDisposed)
            {
                _frmLoaiMayMocList = new frmLoaiMayMocList();
                _frmLoaiMayMocList.MdiParent = form;
                _frmLoaiMayMocList.WindowState = FormWindowState.Maximized;
                _frmLoaiMayMocList.Show();
            }
            else
            {
                _frmLoaiMayMocList.Activate();
            }
        }
        public void ShowFormCongCuDungCuList()
        {
            if (_frmCongCuDungCuList == null || _frmCongCuDungCuList.IsDisposed)
            {
                _frmCongCuDungCuList = new frmCongCuDungCuList();
                _frmCongCuDungCuList.MdiParent = form;
                _frmCongCuDungCuList.WindowState = FormWindowState.Maximized;
                _frmCongCuDungCuList.Show();
            }
            else
            {
                _frmCongCuDungCuList.Activate();
            }
        }

        //Detail
        //Máy
        public void ShowFormMayMocDetail(Guid Id)
        {
            _frmMayMocDetail = new frmMayMocDetail();
            _frmMayMocDetail.Id = Id;
            _frmMayMocDetail.ShowDialog();
        }
        public void ShowFormMayMocDetail(frmMayMocDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        //Thành phẩm
        public void ShowFormThanhPhamDetail(Guid Id)
        {
            _frmThanhPhamDetail = new frmThanhPhamDetail();
            _frmThanhPhamDetail.Id = Id;
            _frmThanhPhamDetail.ShowDialog();
        }
        public void ShowFormThanhPhamDetail(frmThanhPhamDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
       
        
       
       
        //Thép đặc
        public void ShowFormThepDacDetail(Guid Id)
        {
            _frmThepDacDetail = new frmThepDacDetail();
            _frmThepDacDetail.Id = Id;
            _frmThepDacDetail.ShowDialog();
        }
        public void ShowFormThepDacDetail(frmThepDacDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        //Thép lưới
        public void ShowFormThepLuoiDetail(Guid Id)
        {
            _frmThepLuoiDetail = new frmThepLuoiDetail();
            _frmThepLuoiDetail.Id = Id;
            _frmThepLuoiDetail.ShowDialog();
        }
        public void ShowFormThepLuoiDetail(frmThepLuoiDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        //Thép ống
        public void ShowFormThepOngDetail(Guid Id)
        {
            _frmThepOngDetail = new frmThepOngDetail();
            _frmThepOngDetail.Id = Id;
            _frmThepOngDetail.ShowDialog();
        }
        public void ShowFormThepOngDetail(frmThepOngDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        //Thép tấm
        public void ShowFormThepTamDetail(Guid Id)
        {
            _frmThepTamDetail = new frmThepTamDetail();
            _frmThepTamDetail.Id = Id;
            _frmThepTamDetail.ShowDialog();
        }
        public void ShowFormThepTamDetail(frmThepTamDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        //Tôn
        public void ShowFormTonDetail(Guid Id)
        {
            _frmTonDetail = new frmTonDetail();
            _frmTonDetail.Id = Id;
            _frmTonDetail.ShowDialog();
        }
        public void ShowFormTonDetail(frmTonDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        //Mác vật tư
        public void ShowFormMacVatTuDetail(Guid Id)
        {
            _frmMacVatTuDetail = new frmMacVatTuDetail();
            _frmMacVatTuDetail.Id = Id;
            _frmMacVatTuDetail.ShowDialog();
        }
        public void ShowFormMacVatTuDetail(frmMacVatTuDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        public void ShowFormMacVatTuDetail(frmMacVatTuDetail item, Guid Id,string tenLoaiVatTu)
        {
            item.Id = Id;
            item.TenLoaiVatTu = tenLoaiVatTu;
            item.ShowDialog();
        }
        //Đối tác
        public void ShowFormDoiTacDetail(Guid Id)
        {
            _frmDoiTacDetail = new frmDoiTacDetail();
            _frmDoiTacDetail.Id = Id;
            _frmDoiTacDetail.ShowDialog();
        }
        public void ShowFormDoiTacDetail(frmDoiTacDetail item, Guid Id)
        {
            if (item == null) return;
            item.Id = Id;
            item.ShowDialog();
        }
        //Người
        public void ShowFormNguoiDaiDienDetail(Guid Id)
        {
            _frmNguoiDaiDienDetail = new frmNguoiDaiDienDetail();
            _frmNguoiDaiDienDetail.Id = Id;
            _frmNguoiDaiDienDetail.ShowDialog();
        }
        public void ShowFormNguoiDaiDienDetail(frmNguoiDaiDienDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        //Đơn vị tính
        public void ShowFormDonViTinhDetail(Guid Id)
        {
            _frmDonViTinhDetail = new frmDonViTinhDetail();
            _frmDonViTinhDetail.Id = Id;
            _frmDonViTinhDetail.ShowDialog();
        }
        public void ShowFormDonViTinhDetail(frmDonViTinhDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        //Loại Máy móc
        public void ShowFormLoaiMayMocDetail(Guid Id)
        {
            _frmLoaiMayMocDetail = new frmLoaiMayMocDetail();
            _frmLoaiMayMocDetail.Id = Id;
            _frmLoaiMayMocDetail.ShowDialog();
        }
        public void ShowFormLoaiMayMocDetail(frmLoaiMayMocDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }
        //Công cụ dụng cụ
        public void ShowFormCongCuDungCuDetail(Guid Id)
        {
            _frmCongCuDungCuDetail = new frmCongCuDungCuDetail();
            _frmCongCuDungCuDetail.Id = Id;
            _frmCongCuDungCuDetail.ShowDialog();
        }
        public void ShowFormCongCuDungCuDetail(frmCongCuDungCuDetail item, Guid Id)
        {
            item.Id = Id;
            item.ShowDialog();
        }

        public Access(Form newForm)
        {
            form = newForm;
        }
        public Access()
        { 
        }
    }
}
